package com.cheng.controller;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.cheng.pojo.dto.EditGradeDto;
import com.cheng.pojo.dto.EditSummaryDto;
import com.cheng.pojo.dto.ListSummaryDto;
import com.cheng.pojo.dto.ListTwoIndexDto;
import com.cheng.pojo.vo.Result;
import com.cheng.pojo.vo.RocketPeople;
import com.cheng.pojo.vo.RocketScoreStatus;
import com.cheng.pojo.vo.RocketStatus;
import com.cheng.service.ISummaryService;
import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

// @CrossOrigin
@RestController
@RequestMapping("/summary")
public class SummaryController {
    @Resource
    private ISummaryService summaryService;

    // 成绩申诉接口
    @RequestMapping("/addGradesReview")
    public Result addGradesReview(EditGradeDto editGradeDto, HttpServletRequest request){
        String unit = request.getParameter("num");
        if (StringUtils.isBlank(unit)){
            return Result.error(401,"参数传递错误（num）");
        }
        return summaryService.addGrade(editGradeDto);
    }

    // 获取二级指标的接口
    @RequestMapping("/listTwoIndex")
    public Result listTwoIndex(ListTwoIndexDto listTwoIndexDto, HttpServletRequest request){
        String unit = request.getParameter("unit");
        if (StringUtils.isBlank(unit)){
            return Result.error(401,"参数传递错误（unit）");
        }
        return summaryService.listTwoIndex(listTwoIndexDto);
    }

    // 修改summary的总接口
    @RequestMapping("/editSummary")
    public Result editSummary(EditSummaryDto editSummaryDto, HttpServletRequest request){
        String flag = request.getParameter("flag");
        if (StringUtils.isBlank(flag)){
            return Result.error(401,"参数传递错误（flag）");
        }
        String statusFlag = request.getParameter("statusFlag");
        if (StringUtils.isBlank(statusFlag)){
            return Result.error(401,"参数传递错误（statusFlag）");
        }
        String unit = request.getParameter("unit");
        if (StringUtils.isBlank(unit)){
            return Result.error(401,"参数传递错误（unit）");
        }
        String comeName = request.getParameter("comeName");
        if (StringUtils.isBlank(comeName)){
            return Result.error(401,"参数传递错误（comeName）");
        }
        return summaryService.editSummary(editSummaryDto);
    }

    // 搜索所有汇总数据
    @RequestMapping("/listSummary")
    public Result listSummary(ListSummaryDto listSummaryDto, HttpServletRequest request){
        String year = request.getParameter("year");
        if (StringUtils.isBlank(year)){
            return Result.error(401,"参数传递错误（year）");
        }
        return summaryService.listSummary(listSummaryDto);
    }
}
